#!/bin/sh
#BLURB="Select/deselect LizardFS services"
#
# /var/log/setup/setup.lizardfs-services
#
# LizardFS configuration script.  Lets you choose which of four
# it's processes will run on this box.
#
TMP=/var/log/setup/tmp
if [ ! -d $TMP ]; then
	mkdir -p $TMP
fi
T_PX="$1"
cd $T_PX
rm -f $TMP/tmpscript

cat << EOF > $TMP/tmpscript
dialog --title "CHOOSE LizardFS SERVICES TO RUN ON THIS BOX" --item-help --checklist \\
"The selected services will be started by rc.lizardfs init script.\\n\\n
1. You need exactly ONE master server (run on your best machine)\\n
2. You should have one, two or more meta loggers\\n
3. On most machines you will need chunk server process only \\
(therefore rc.lizardfs-chunkserver is enabled by default.\\n\\n
Press the ENTER key when you are finished." \\
19 70 4 \\
EOF

if [ -r /etc/rc.d/rc.lizardfs-master ]; then
	if [ -x /etc/rc.d/rc.lizardfs-master ]; then
		MFS_MASTER=on
	else
		MFS_MASTER=off
	fi
	cat << EOF >> $TMP/tmpscript
		"rc.lizardfs-master" "LizardFS master server" $MFS_MASTER "The Master Server is a central point of LizardFS.  You need exactly ONE." \\
EOF
fi

if [ -r /etc/rc.d/rc.lizardfs-cgiserv ]; then
	if [ -x /etc/rc.d/rc.lizardfs-cgiserv ]; then
		MFS_CGI=on
	else
		MFS_CGI=off
	fi
	cat << EOF >> $TMP/tmpscript
		"rc.lizardfs-cgiserv" "LizardFS Web Console" $MFS_CGI "The CGI server displays information on LizardFS status." \\
EOF
fi

if [ -r /etc/rc.d/rc.lizardfs-metalogger ]; then
	if [ -x /etc/rc.d/rc.lizardfs-metalogger ]; then
		MFS_METALOGGER=on
	else
		MFS_METALOGGER=off
	fi
	cat << EOF >> $TMP/tmpscript
		"rc.lizardfs-metalogger" "Metalogger process" $MFS_METALOGGER "Metalogger is a backup machine for Master Server.  Deploy some in your network." \\
EOF
fi

if [ -r /etc/rc.d/rc.lizardfs-chunkserver ]; then
	if [ -x /etc/rc.d/rc.lizardfs-chunkserver ]; then
		MFS_CHUNK=on
	else
		MFS_CHUNK=off
	fi
	cat << EOF >> $TMP/tmpscript
		"rc.lizardfs-chunkserver" "Chunk server process" $MFS_CHUNK "The Chunk Server stores actual filesystem data in chunks.  All other machines." \\
EOF
fi

cat << EOF >> $TMP/tmpscript
	2> $TMP/reply
EOF

. $TMP/tmpscript

if [ ! $? = 0 ]; then
	rm -f $TMP/reply $TMP/tmpscript
	exit
fi

for service in rc.lizardfs-cgiserv rc.lizardfs-chunkserver rc.lizardfs-master rc.lizardfs-metalogger; do
	if [ -f /etc/rc.d/$service ]; then
		if grep -w $service $TMP/reply 1> /dev/null ; then
			chmod 755 /etc/rc.d/$service
		else
			chmod 644 /etc/rc.d/$service
		fi
	fi
done

rm -f $TMP/reply $TMP/tmpscript

